import * as types from '../constants/recruitTypes'
import API from '../../api/request'

export function recruit () {
  return dispatch => {
    getRecruitInfo(dispatch)
  }
}

// TODO
async function getRecruitInfo (dispatch) {
  const url = '/api/user/myApprentice'
  let recruitInfo = ''
  let res = await API.post(url)
  if (global.isApiFetchingSuccess(res)) {
    recruitInfo = res.data
    dispatch(apiGetSuccess(recruitInfo))
  } else {
    dispatch(apiGetError(res.message))
  }
}

function apiGetSuccess (data) {
  return {
    type: types.RECRUIT_IN_SUCCESS,
    data
  }
}

function apiGetError (err) {
  return {
    type: types.RECRUIT_IN_ERROR,
    err
  }
}
